package top.kaoshanji.r3ch11c;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/5/9 14:33
 */
public class BbtForum {

    public ForumDao forumDao;

    public TopicDao topicDao;

    public PostDao postDao;

    @Autowired
    public void setForumDao(ForumDao forumDao) {
        this.forumDao = forumDao;
    }

    @Autowired
    public void setTopicDao(TopicDao topicDao) {
        this.topicDao = topicDao;
    }

    @Autowired
    public void setPostDao(PostDao postDao) {
        this.postDao = postDao;
    }

    public void addTopic(Topic topic) throws Exception {
        topicDao.addTopic(topic);
        // 代码清单-r3ch11c-382页a：事务提交的示例，需要在事务属性配置里指定
//		if(true) throw new PessimisticLockingFailureException("fail"); // 抛出此异常依然提交事务，上面的dao操作提交，下面的因为异常不能执行
        postDao.addPost(topic.getPost());
    }

    public Forum getForum(int forumId) {
        return forumDao.getForum(forumId);
    }

    public void updateForum(Forum forum) {
        forumDao.updateForum(forum);
    }

    public int getForumNum() {
        return forumDao.getForumNum();
    }

}
